home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: C constant expression declarations
- Date: 15 Feb 1996 07:57:31 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4fvl5cINN94q@keats.ugrad.cs.ubc.ca>
- References: <31229735.41C67EA6@isi.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <31229735.41C67EA6@isi.com>, J.R. Stoner <jstoner@isi.com> wrote:
- >This is a query (I have checked the FAQ) into something that strikes me
- >as a dumbfoundedly stupid issue, but I will ask it anyway :)
- >
- >Normally, I will do things such as:
- >
- > #define EXPR1 1
- > #define EXPR2 2
- >
- >...and so on. Lately, I have been observing in code from other people
- >equivalent declarations such as:
- >
- > #define EXPR1 (1)
- > #define EXPR2 (2)
-
- This does not buy you anything at all, since the thing you are bracketing
- has only one constituent: it's not a compound expression.
-
- It's useful when you define macros for entire expressions, because it ensures
- that the expression will always parse as a unit, taking precedence over any
- surrounding operators that may appear alongside the macro expansion.
-
- >I have seen in the FAQ the business of declaring varargs macros that
- >are invoked with something like:
- >
- > DEBUG(("This is a printf string\n"))
- >
- >...but it does not seem relevant here.
-
- It is. Without the double parentheses, you would not be able to do multiple
- arguments. That is, writing
-
- DEBUG("Error %d writing to toaster %d!\n",err,toa)
-
- would be interpreted as passing three arguments to the DEBUG macro.
- On the other hand, the _single_ argument of
-
- DEBUG(("Error %d writing to toaster %d!\n",err,toa))
-
- expands as ("error %d ... \n",err,toa), which can be glued behind, say, a
- printf.
-
- >Is there, in fact, a reason for putting parens around "simple" constant
- >expressions? A reason that did not exist previously?
-
- Absolutely not. Some programmers just become irrationally paranoid over the
- years. It's easier to just put parentheses around everything than to think
- about it.
-
- On the other hand, I'm a minimalist. I tend to eliminate parens as much as
- possible to the point that some compilers warn me to put the damn things back
- in for clarity. :)
- --
-
-